package com.web.boot.web.cms;

import com.blue.core.dict.HttpMethod;
import com.blue.core.dict.annotation.DictParser;
import com.blue.http.annotation.Http;
import com.blue.http.message.HttpRequest;
import com.blue.http.message.View;
import com.blue.http.message.ViewBuilder;
import com.web.cms.doc.facade.DocCommentFacade;
import com.web.cms.doc.facade.DocFacade;
import com.web.cms.doc.message.DocCommentRequest;
import com.web.core.util.Const;
import org.springframework.stereotype.Controller;

import javax.annotation.Resource;

@Controller("cmsDocCommentController")
@Http(url = "/cms")
public class DocCommentController
{
	@Resource
	private DocCommentFacade docCommentFacade;
	@Resource
	private DocFacade docFacade;
	
	private DictParser dictParser = DictParser.getInstance();
	
	public DocCommentController()
	{
	}
	
	@Http(url = "/doc_comment_list", method = HttpMethod.GET)
	public View listGet(HttpRequest request)
	{
		DocCommentRequest docCommentRequest = request.getQueryObject(DocCommentRequest.class);
		ViewBuilder builder = View.createBuilder();
		if (docCommentRequest.getDocId() != null)
		{
			builder.put("parentModel", docFacade.getOne(docCommentRequest.getDocId()));
		}
		return builder.setView("/cms/doc_comment_list")
				.put("model", docCommentRequest)
				.put("map", dictParser.getStringMap())
				.put("page", docCommentFacade.listPage(docCommentRequest, Const.PAGE_START, Const.PAGE_SIZE))
				.build();
	}
	
	@Http(url = "/doc_comment_list", method = HttpMethod.POST)
	public View listPost(HttpRequest request)
	{
		DocCommentRequest docCommentRequest = request.getPostObject(DocCommentRequest.class);
		int start = request.getPostInt("start", Const.PAGE_START);
		return View.createBuilder().setView("/cms/doc_comment_list_grid")
				.put("page", docCommentFacade.listPage(docCommentRequest, start, Const.PAGE_SIZE))
				.build();
	}
	
}
